<template>
  <div class="back">
    <div class="box">
      <div class="left">
        <div class="lFont">
          <i class="el-icon-postcard"></i>
          <div style="width: 120px">
            <span class="font" style="font-weight: bold;">鳞次栉比</span>
            <span class="font" style="font-size: 0.8em">博物馆馆藏种类繁多</span>
          </div>
        </div>
        <div class="lFont">
          <i class="el-icon-chat-line-square"></i>
          <div style="width: 120px">
            <span class="font" style="font-weight: bold;">叩问古今</span>
            <span class="font" style="font-size: 0.8em">近距离观看历史文物</span>
          </div>
        </div>
        <div class="lFont">
          <i class="el-icon-reading"></i>
          <div style="width: 120px">
            <span class="font" style="font-weight: bold;">润物无声</span>
            <span class="font" style="font-size: 0.8em">感受文化历史厚重感</span>
          </div>
        </div>
      </div>
      <div style="float: left">
        <el-form class="form" :model="formData" ref="formRef">
          <div style="margin-bottom: 10%">
            <a style="align-content: center;font-size: 1.5em;">用户注册</a>
          </div>
          <el-form-item style="margin-top: 2%" prop="username">
            <el-input style="width: 100%" v-model="formData.userAccount" placeholder="请输入用户姓名"></el-input>
          </el-form-item>
          <el-form-item style="margin-top: 2%" prop="userEmail">
            <el-input style="width: 100%" v-model="formData.userEmail" placeholder="请输入邮件地址"></el-input>
          </el-form-item>
          <el-form-item>
            <el-input style="width: 60%" v-model="formData.captcha" placeholder="请输入验证码"></el-input>
            <el-button style="margin-left: 5%; width: 35%" type="primary" @click="getCaptcha">获取验证码</el-button>
          </el-form-item>
          <el-form-item prop="password">
            <el-input style="width: 100%" v-model="formData.userPassword" placeholder="请输入密码"
                      show-password></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input style="width: 100%" v-model="formData.checkPassword" placeholder="请再次输入密码"
                      show-password></el-input>
          </el-form-item>
          <el-form-item>
            <el-button style="width: 100%" type="primary" @click="register">注册</el-button>
          </el-form-item>

        </el-form>
      </div>
    </div>
  </div>
</template>


<script>
import {userCaptcha, userRegister} from "@/api/request";

export default {
  data() {
    return {
      uuid: '',
      formData: {
        uuid: '',
        userAccount: '',
        userEmail: '',
        captcha: '',
        userPassword: '',
        checkPassword: ''
      },
    }
  },
  methods: {
    register() {
      this.formData.uuid = this.uuid
      userRegister(this.formData).then(
          res => {
            if (res.data.code === 1) {
              this.$message.success(res.data.description)
              this.$router.push('/login')
            } else {
              this.$message.error(res.data.message)
            }
          }
      )
    },
    getCaptcha() {
      userCaptcha(this.formData.userEmail, this.uuid).then(
          res => {
            if (res.data.code === 1) {
              this.$message.success(res.data.description)
            }
          }
      )
    },
    getUuid() {
      return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        const r = Math.random() * 16 | 0,
            v = c === 'x' ? r : (r & 0x3 | 0x8);
        return v.toString(16);
      });
    }
  },
  mounted() {
    this.uuid = this.getUuid()
    console.log(this.uuid)
  }
}

</script>


<style scoped>
.el-form-item >>> .el-input__inner {
  border-radius: 10px !important;
}

/*按钮悬浮*/
.el-button:hover {
  background: #00bebd !important;
  color: white !important;
  border-color: #00bebd !important;
  border-radius: 10px !important;
}

/*按钮点击*/
.el-button:focus {
  background: #00bebd !important;
  color: white !important;
  border-color: #00bebd !important;
  border-radius: 10px !important;
}

.el-button--primary {
  background: linear-gradient(90deg, #00bebd, #01a7a7);
  border: none;
  border-radius: 10px !important;
}

.back {
  height: 708px;
  background: #00c1c1 url(../../assets/back.png) bottom/100% auto no-repeat;
}

.form {
  width: 100%;
  margin-top: 10%;
  margin-left: 15%;
}

.box {
  position: absolute;
  width: 40%;
  height: 65%;
  margin-left: 30%;
  //margin-top: 10%;
  border-radius: 28px;
  top: 18%;
  background: #fff;
  box-shadow: 0 6px 8px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
}

.left {
  background: linear-gradient(214deg, #dffbff, #faf6f3);
  float: left;
  width: 32%;
  height: 100%;
  border-radius: 28px 0 0 28px;
}

.font {
  float: left;
  display: inline-block;
  vertical-align: top;
  font-size: 1em;
  text-align: center;
  margin-left: 2%;
}

.lFont {
  margin-top: 20%;
  cursor: pointer;
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  flex-direction: row;
  align-content: center;
  flex-wrap: nowrap;
}

[class*=" el-icon-"], [class^=el-icon-] {
  font-size: 3em;
}
</style>
